package com.xb.controller;

import com.xb.entity.Stock;
import com.xb.service.IStockService;
import com.xb.util.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * entityController
 * /api/stock
 */
@RestController
@RequestMapping("/api/stock")
public class StockController {
    @Autowired
    private IStockService stockService;

    @RequestMapping("/page")
    @RequiresPermissions("system:stock:page")
    public Object findPage(Stock obj, @RequestParam(value = "page", defaultValue = "1") Integer page,
                           @RequestParam(value = "limit", defaultValue = "10") Integer limit) {
        return stockService.selectStockList(obj, page, limit);
    }

    /**
     * 添加
     */
    @PostMapping
    @RequiresPermissions("system:stock:add")
    public Object add(@RequestBody Stock obj) {
        Result result = new Result();
        result.setMessage("失败！");
        return result;
    }

    /**
     * 修改
     */
    @PutMapping
    @RequiresPermissions("system:stock:update")
    public Object update(@RequestBody Stock obj) {
        Result result = new Result();
        result.setMessage("失败！");
        return result;
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    @RequiresPermissions("system:stock:del")
    public Object del(@PathVariable Integer id) {
        Result result = new Result();
        if(stockService.deleteStockById(id)>0){
            result.setMessage("删除成功！");
            result.setStatus(Result.RESPONSE_SUCCESS);
        }else{
            result.setMessage("删除失败！");
        }
        return result;
    }

}
